package com.lfg.leetcode.leetcode300;

import java.util.Arrays;

public class No322coinChange {
    public static void main(String[] args) {
        int ret = coinChange(new int[]{1, 2, 5, 10}, 7);
        System.out.println("[" + ret + "]");

    }


    public static int coinChange(int[] coins, int amount) {
        Arrays.sort(coins);
        int[] dp = new int[amount + 1];
        Arrays.fill(dp, amount + 1);
        dp[0] = 0;
        for (int i = 0; i <= amount; i++) {
            for (int c : coins) {
                int index = i - c;
                if (index >= 0) {
                    dp[i] = Math.min(dp[i], dp[index]+ 1) ;
                }else {
                    break;
                }
            }
        }
        return dp[amount] > amount ? -1 : dp[amount];
    }
}
